from drf_movie_rimi.settings import BASE_DIR
import os


# 找到我们要写入的总文件夹

base_dir = os.path.join(BASE_DIR,'file_test')
######## 1. 使用python打开文件

def test1():
    file = os.path.join(base_dir,'test1.txt')
    with open(file,'w+') as f:
        f.write('hello worasdfld')


#需要使用追加模式来循环写入 不然会被覆盖
def test2():
    file = os.path.join(base_dir,'test2.txt')
    with open(file,'a+') as f:

        i = 0
        while i < 10000:
            i += 1
            f.write('hello worasdfld\n')

#读取文件 读取大型文件或者打印大型文件的时候需要循环遍历

def test3():
    file = os.path.join(base_dir,'test2.txt')
    with open(file,'r') as f:
        datas = f.readlines()
        for i in datas:
            print(i)

        pass

def test4():
    from urllib import parse

    url_test = 'www.baidu.com?'
    url_params = 'a=阿凡达拉水电费&b=发的说法发?生?的浪费阿斯蒂芬'
    print(url_test+ parse.quote(url_params))

if __name__ == "__main__":
    test4()